﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PersonaLibrary.ViewModel.PrintViewModel
{
    internal class PrintChildVM<T> : BaseViewModel<T>
        where T : View.IView, new()
    {
        private bool _isWindowOpened = false;
        private bool _disposed;

        public bool IsWindowOpened
        {
            get
            {
                return _isWindowOpened;
            }
        }

        protected override void OnViewCreated()
        {
            base.OnViewCreated();
            View.Loaded += View_Loaded;
            View.Closing += View_Closing;
        }

        void View_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            View.Hide();
            e.Cancel = !_disposed;
            _isWindowOpened = false;
            RisePropertyChanged("IsWindowOpened");
        }

        void View_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            _isWindowOpened = true;
            RisePropertyChanged("IsWindowOpened");
        }

        public override void Dispose()
        {
            _disposed = true;
            View.Close();
            base.Dispose();
        }
    }
}
